layui.use(['form','jquery','jquery_cookie'], function (){
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        $ = layui.jquery_cookie($);


    form.on('submit(saveBtn)', function (data){
        console.log(data.field);

        // 发送ajax请求
        $.ajax({
            type: "post",
            url: ctx+"/user/update_password",
            data: {
                oldPwd:$("[name='old_password']").val(),
                newPwd:$("[name='new_password']").val(),
                confirmPwd:$("[name='again_password']").val(),
            },
            success: function (data){
                // 如果code==200则表示修改密码成功
                if (data.code==200){
                    console.log("修改密码成功");

                    layer.msg("修改成功！系统即将退出！！", function (){
                        // 清空cookie
                        $.removeCookie("id",{domain:"localhost",path:"/mall"});
                        $.removeCookie("username",{domain:"localhost",path:"/mall"});

                        // 跳转到登录界面
                        window.parent.location.href = ctx + "/index";
                    });

                }else {
                    console.log("修改失败！");
                    // 弹出提示框
                    layer.msg(data.msg,{icon:5});
                }
            }
        });

    });

});
